package Generic;

import java.util.Objects;

public class Demo1 {
    public static void main(String[] args) {
        Test1<String> test1 = new Test1<>();
        test1.setT("James");
        Test1<String> test11 = new Test1<>();
        test11.setT("Kobe");

        System.out.println(test1.getT());
        System.out.println(test11.getT());
        System.out.println(test1.equals(test11));

        Test1<Integer> test2 = new Test1<>(36);
        Test1<Integer> test22 = new Test1<>(42);

        System.out.println(test2.getT());
        System.out.println(test22.getT());
        System.out.println(test2.equals(test22));

        Test2<String> test3 = new Test2<>();
        test3.setM("KD");
        System.out.println(test1.equals(test3));

    }
}
class Test1<T> {
    private T t;

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    public Test1(){

    }

    public Test1(T t) {
        this.t = t;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Test1<?> test1 = (Test1<?>) o;
        return Objects.equals(t, test1.t);
    }

    @Override
    public int hashCode() {
        return Objects.hash(t);
    }
}
class Test2<M>{
    private M m;

    public M getM() {
        return m;
    }

    public void setM(M m) {
        this.m = m;
    }

}
